﻿using System;
using System.Diagnostics;
using System.IO;

namespace DocX_WordDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputFilePath = "../../Document/";
            string outputFilePath = @"Result\";
            string separatorLine=new string('-',30);

            UpdateDirectory(outputFilePath);

            #region 1. Conversion
            Conversion.ConvertToDoc(inputFilePath + "Sample01.docx", outputFilePath + "ToDoc.doc");
            Console.WriteLine("ConvertToDoc finish.");

            Conversion.ConvertToImage(inputFilePath + "Sample01.docx", outputFilePath + "ToImage");
            Console.WriteLine("ConvertToImage finish.");

            Conversion.ConvertToPdf(inputFilePath + "Sample01.docx", outputFilePath + "ToPdf.pdf");
            Console.WriteLine("ConvertToPdf finish.");

            Conversion.ConvertToRtf(inputFilePath + "Sample01.docx", outputFilePath + "ToRtf.rtf");
            Console.WriteLine("ConvertToRtf finish.");

            Conversion.ConvertToTxt(inputFilePath + "Sample02.docx", outputFilePath + "ToTxt.txt");
            Console.WriteLine("ConvertToTxt finish.");

            Console.WriteLine(separatorLine);

            #endregion

            #region 2. Context Operation
            Context.InsertComment(inputFilePath + "Sample01.docx", outputFilePath + "InsertComment.docx");
            Console.WriteLine("InsertComment finish.");

            Context.InsertEndnote(inputFilePath + "Sample01.docx", outputFilePath + "InsertEndnote.docx");
            Console.WriteLine("InsertEndnote finish");

            Context.InsertFootnote(inputFilePath + "Sample01.docx", outputFilePath + "InsertFootnote.docx");
            Console.WriteLine("InsertFootnote finish.");

            Context.InsertSubSuperScript(inputFilePath + "Sample02.docx", outputFilePath + "InsertSubSuperScript.docx");
            Console.WriteLine("InsertSubSuperScript finish.");

            Context.InsertTextbox(inputFilePath + "Sample02.docx", outputFilePath + "InsertTextbox.docx");
            Console.WriteLine("InsertTextbox finish.");

            Context.InsertWatermark(inputFilePath + "Sample02.docx", outputFilePath + "InsertWatermark.docx");
            Console.WriteLine("InsertWatermark finish.");

            Context.FindAndHighlight(inputFilePath + "Sample01.docx", outputFilePath + "FindAndHighlight.docx");
            Console.WriteLine("FindAndHighlight finish.");

            Console.WriteLine(separatorLine);

            #endregion

            #region 3. Mail Merge Operation
            MailMerge.DoMailMerge(inputFilePath + "Fax01.docx", outputFilePath + "SimpleMailMerge.docx");
            Console.WriteLine("DoMailMerge finish.");

            MailMerge.DoMailMergeEvent(inputFilePath + "Fax02.docx", outputFilePath + "MailMergeEvent.docx");
            Console.WriteLine("DoMailMergeEvent finish.");

            MailMerge.DoNestedMailMerge(inputFilePath + "Invoice.docx", outputFilePath + "NestedMailMerge.docx");
            Console.WriteLine("DoNestedMailMerge finish.");

            Console.WriteLine(separatorLine);

            #endregion

            #region 4. Form Field Operation
            FormFieldOp.CreateFormField(inputFilePath + "Form.xml", outputFilePath + "CreateFormField.docx");
            Console.WriteLine("CreateFormField finish.");

            FormFieldOp.FillFormField(inputFilePath + "UserForm.docx", outputFilePath + "FillFormField.docx");
            Console.WriteLine("FillFormField finish.");

            Console.WriteLine(separatorLine);

            #endregion

            #region 5. Miscellaneous
            Miscellaneous.Encrypt(inputFilePath + "Sample01.docx", outputFilePath + "Encrypt.docx", "Ish'kafel");
            Console.WriteLine("Encrypt finish.");

            Miscellaneous.InsertOLEObject(inputFilePath + "Sample02.docx", outputFilePath + "OLEObject.docx");
            Console.WriteLine("InsertOLEObject finish.");

            Miscellaneous.PageSetup(inputFilePath + "Sample01.docx", outputFilePath + "PageSetup.docx");
            Console.WriteLine("PageSetup finish.");

            Miscellaneous.RemoveMacro(inputFilePath + "Macros.docm", outputFilePath + "RemoveMacro.docx");
            Console.WriteLine("RemoveMacro finish.");

            Miscellaneous.SetViewMode(inputFilePath + "Sample01.docx", outputFilePath + "SetViewMode.docx");
            Console.WriteLine("SetViewMode finish");

            Console.WriteLine(separatorLine);

            #endregion

            Process.Start("explorer.exe", outputFilePath);
            Console.WriteLine("Press any key to quit...");
            Console.ReadKey();

        }

        static void UpdateDirectory(string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }

    }
}
